package com.mario.service;

import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.validator.AbstractValidator;

public class ProductValidator extends AbstractValidator {

	public void validate(ValidationContext vc) {
		String description = (String) vc.getProperties("description")[0].getValue();
		Double price = (Double) vc.getProperties("price")[0].getValue();
		
		if (description == null || "".equals(description))
			this.addInvalidMessage(vc, "description", "You must enter a description");
		
		if (price.isNaN() || price < 0)
			this.addInvalidMessage(vc, "price", "You must specify a valid price");
	}

}
